$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        chart_1 :null,
        chart_2 :null,
        config:null,
        init:function () {
            this.funObj().loadChart();
            // this.funObj().showMap();
            this.listener();
        },
        listener:function () {

        },
        funObj:function () {
            var $this = this;
            return {
                loadChart:function () {
                    //柱状图
                    var myChart = echarts.init(document.getElementById('chart_1'));
                    var labelOption = {
                        normal: {
                            show: true,
                            position: 'top',
                            distance: 8,
                            align: 'center',
                            verticalAlign: 'bottom',
                            rotate: 0,
                            formatter: '{c} {a}',
                            fontSize: 16,
                            rich: {
                                name: {
                                    textBorderColor: '#fff'
                                }
                            }
                        }
                    };
                    var chartOption = {
                        title : {
                            text: '盒子在线情况（学校总数：' + chart_data.total + '）',
                            left: 'left'
                        },
                        color: ['#5AB1EF', '#2EC7C9', '#D87A80'],
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: {
                            data: ['总计', '在线', '离线'],
                            // type: 'scroll',
                            // orient: 'vertical',
                            right: 10,
                            top: 20,
                            bottom: 20
                        },
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center'
                        },
                        calculable: false,
                        xAxis: [
                            {
                                type: 'category',
                                axisTick: {show: true},
                                data: ['文件盒子', '课堂盒子', '其他盒子']
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: [
                            {
                                name: '总计',
                                type: 'bar',
                                barGap: 0,//间隙
                                label: labelOption,
                                data: chart_data.all
                            },
                            {
                                name: '在线',
                                type: 'bar',
                                label: labelOption,
                                data: chart_data.online
                            },
                            {
                                name: '离线',
                                type: 'bar',
                                label: labelOption,
                                data: chart_data.offline
                            }
                        ]
                    };
                    myChart.setOption(chartOption);

                    //饼图
                    var myPie = echarts.init(document.getElementById('chart_2'));
                    var option = {
                        color: ['#97B552', '#5AB1EF', '#E5CF0D', '#D87A80', '#FFB980', '#2EC7C9', '#8D98B3', '#B6A2DE'],
                        tooltip:{
                            trigger:'item',
                            formatter: "{a} <br/> {b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            data: chart_model.legend
                        },
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        series: [
                            {
                                'name': '型号统计',
                                'type':  'pie',
                                'radius': '60%',
                                'center': ['50%', '60%'],
                                'data': chart_model.series
                            }
                        ]
                    };
                    myPie.setOption(option);
                }
            };
        }
    }
};